package xyz.zichengdulin.mapper;

import org.apache.ibatis.annotations.*;
import xyz.zichengdulin.pojo.Student;
import xyz.zichengdulin.pojo.StudentQueryParam;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {

    /**
     * 学员条件分页查询
     *
     * @param studentQueryParam
     * @return
     */
    List<Student> page(StudentQueryParam studentQueryParam); //使用StudentQueryParam封装,条件查询条件


    /**
     * 根据ids批量删除学员
     *
     * @param ids
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 添加学员信息
     * @param student
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")    //获取到生成的主键--主键返回
    @Insert("insert into student(name,no,gender,phone,id_card,is_college,address,degree,graduation_date,clazz_id,create_time,update_time)" +
            "values(#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId},#{createTime},#{updateTime})")
    void insert(Student student);

    /**
     * 根据id查询学生信息
     * @param id
     * @return
     */
    @Select("select * from student s where s.id = #{id} ")
    Student getInfoById(Integer id);

    /**
     * 更新学员信息
     * @param student
     */
    void update(Student student);

    /**
     * 修改学生违规信息
     * @param id
     * @param score
     */
    void violate(Integer id, Integer score);

    /**
     * 统计学员人数信息
     * @return
     */
    @MapKey("clz")
    List<Map<String, Object>> countStudentCountData();

    /**
     * 统计学员学历信息
     * @return
     */
    @MapKey("name")
    List<Map<String, Object>> countStudentDegreeData();
}
